<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>全球国家数据</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    <div class="layui-header">
        <div class="layui-logo"><strong>高校健康上报系统</strong></div>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item ">
                    <a href="/zhuye"><i class="layui-icon layui-icon-home"></i>  用户主页</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/userinfo"><i class="layui-icon layui-icon-survey"></i>  个人信息上报</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/record"><i class="layui-icon layui-icon-log"></i>  上报记录</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/china"><i class="layui-icon layui-icon-list"></i>  国内省份数据</a>
                </li>
                <li class="layui-nav-item layui-this">
                    <a href="/global1"><i class="layui-icon layui-icon-list"></i>  全球国家数据</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/regional"><i class="layui-icon layui-icon-list"></i>  全球地区数据</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/logout"><i class="layui-icon layui-icon-logout"></i>  退出系统</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div style="padding: 15px;">
            <div id="main" style="width: 1300px;height:525px;"></div>
        </div>

        <div style="padding: 15px;">
            <div class="demoTable">
                查询国家：
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                </div>
                <button class="layui-btn" id="btn" data-type="reload">查询</button>
            </div>
            <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
        </div>
    </div>
</div>

<script src="../layui/layui.js"></script>
<script>
    layui.use('element', function(){
        var element = layui.element;

    });

    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#LAY_table_user'
            ,url:'/data/global'
            ,cellMinWidth: 80
            ,toolbar:true
            ,title:'用户数据表'
            ,totalRow:true
            ,cols: [
                [
                    {field:'country', title: '国家'}
                    ,{field:'latestTotalCases', title: '累计确诊人数', sort: true, align: 'center'}
                    ,{field:'diffFromPrevDay', title: '相较前一天新增确诊人数', sort: true, align: 'center'}
                ]
            ]
            ,id: 'testReload'
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                console.log("key:" + demoReload.val());
                table.reload('testReload', {
                        url: '/data/country'
                        ,where: {
                            country: demoReload.val()
                        }
                    }
                );
            }
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    var myChart = echarts.init(document.getElementById('main'));

    myChart.setOption({
        title: {
            text: '全球疫情感染情况'
        },
        tooltip: {},
        legend: {
            data:['感染人数']
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '感染人数',
            type: 'bar',
            data: []
        }]
    });

    $.get('/data/gorp').done(function (data) {
        myChart.setOption({
            xAxis: {
                data: data.country
            },
            series: [{
                name: '感染人数',
                data: data.num
            }]
        });
    });
</script>
</body>
</html>